
use "${data}ACS2017-2021_finalready.dta" , clear 

	 			
	global outcome married_to_unmarried   married_to_unmarried_v2   unmarried_to_married   unmarried_to_married_v2 ///
					unmarried_to_married_v3 married_to_unmarried_v3   
	

	
	foreach v in $outcome {
		
		rename change_`v' `v'
		g STD_`v'= `v'
		
	}
	* 
	global STD STD_married_to_unmarried STD_married_to_unmarried_v2 STD_unmarried_to_married STD_unmarried_to_married_v2 STD_unmarried_to_married_v3 STD_married_to_unmarried_v3
	
***********************************************************************************************************************	*						
* FIGURE 1 and Figure B.1, for MEN 
************************************************************************************************************************			
	
preserve 
	keep if male==1 
	keep if yrsusa1<21 
collapse (mean)  $outcome  (semean) $STD , by(yrsusa1)

	foreach v in $outcome {
		g upper_`v'= `v' + 1.96*STD_`v'
		g lower_`v'= `v' - 1.96*STD_`v'
	}
	

twoway 	( rarea   upper_married_to_unmarried_v3 lower_married_to_unmarried_v3    yrsusa1 ,    color(gs15)  ) || /// 
		( rarea   upper_unmarried_to_married_v3 lower_unmarried_to_married_v3     yrsusa1 ,   color(gs15)  ) || ///  
		(line   married_to_unmarried_v3 yrsusa1 , lcolor(black) lpattern(dash)  )  ///
	   (line   unmarried_to_married_v3    yrsusa1 ,  lcolor(gs11)  ) ///
         , legend(order(3 "from married to unmarried" 4   "from unmarried to married") region(lwidth(none)) ) ///
		    xtitle("Years in the US")  ytitle("")   ylab(, angle(horizontal)) graphregion(color(white)) name(fig1_A,replace) 
			
			
		
	 graph export "${result}Fig1_panelA.eps", replace 

		  
twoway 	(rarea   upper_married_to_unmarried     lower_married_to_unmarried    yrsusa1 ,    color(gs15)  ) || /// 
		(rarea   upper_married_to_unmarried_v2  lower_married_to_unmarried_v2    yrsusa1 ,   color(gs15)  ) || /// 
		(rarea   upper_unmarried_to_married     lower_unmarried_to_married    yrsusa1 ,    color(gs15) ) || /// 
		(rarea   upper_unmarried_to_married_v2  lower_unmarried_to_married_v2   yrsusa1 ,    color(gs15)  ) || /// 
	    (line   married_to_unmarried yrsusa1 , lcolor(black) lpattern(dash3dot)  )  ///
	    (line   married_to_unmarried_v2  yrsusa1  , lcolor(black) lpattern(shortdash_dot) ) ///
	    (line   unmarried_to_married    yrsusa1 , lcolor(gs11) ) ///
	    (line   unmarried_to_married_v2  yrsusa1  , lcolor(gs11) lpattern(longdash)) ///
         , legend(order(5 "from married" "to unmarried" "assumption 1" 6  "assumption 2" ///
		   7 "from unmarried" "to married" "assumption 1"  8  "assumption 2" ) col(1) region(lwidth(none)) ring(0) position(11) symxsize(5pt) size( medsmall  )     )  xtitle("Years in the US") ytitle("")  ylab(, angle(horizontal)) graphregion(color(white)) name(figB1men,replace) 
			
	 
	 graph export "${result}FigB1_panelA.eps",  replace 

	 
			
 restore


 

***********************************************************************************************************************	*						
* FIGURE 1 and Figure B.1, for WOMEN 
************************************************************************************************************************			
	
preserve 
	keep if male==0 
	keep if yrsusa1<21 
	
collapse (mean)  $outcome  (semean) $STD , by(yrsusa1)

	foreach v in $outcome {
		g upper_`v'= `v' + 1.96*STD_`v'
		g lower_`v'= `v' - 1.96*STD_`v'
	}
	
	twoway 	( rarea   upper_married_to_unmarried_v3 lower_married_to_unmarried_v3    yrsusa1 ,     color(gs15)   ) || /// 
		    ( rarea   upper_unmarried_to_married_v3 lower_unmarried_to_married_v3     yrsusa1 ,    color(gs15)   ) || ///  
		    (line   married_to_unmarried_v3 yrsusa1 , lcolor(black) lpattern(dash)  )  ///
	        (line   unmarried_to_married_v3    yrsusa1 , lcolor(gs11)  ) ///
			, legend(order(3 "from married to unmarried" 4   "from unmarried to married") region(lwidth(none)) ) ///
		    xtitle("Years in the US")  ytitle("")   ylab(, angle(horizontal)) graphregion(color(white)) name(fig1_B,replace) 
	
	graph export "${result}Fig1_panelB.eps",  replace 
	
			
twoway 	(rarea   upper_married_to_unmarried     lower_married_to_unmarried    yrsusa1 ,    color(gs15)  ) || /// 
		(rarea   upper_married_to_unmarried_v2  lower_married_to_unmarried_v2    yrsusa1 ,    color(gs15)  ) || /// 
		(rarea   upper_unmarried_to_married     lower_unmarried_to_married    yrsusa1 ,     color(gs15)  ) || /// 
		(rarea   upper_unmarried_to_married_v2  lower_unmarried_to_married_v2   yrsusa1 ,   color(gs15)   ) || /// 
	    (line   married_to_unmarried yrsusa1 , lcolor(black) lpattern(dash3dot)  )  ///
	    (line   married_to_unmarried_v2  yrsusa1  , lcolor(black) lpattern(shortdash_dot) ) ///
	    (line   unmarried_to_married    yrsusa1 , lcolor(gs11)  ) ///
	    (line   unmarried_to_married_v2  yrsusa1  ,  lcolor(gs11) lpattern(longdash) ) ///
         , legend(order(5 "from married" "to unmarried" "assumption 1" 6  "assumption 2" ///
		   7 "from unmarried" "to married" "assumption 1"  8  "assumption 2" ) col(1) region(lwidth(none)) ring(0) position(11) symxsize(5pt) size( medsmall  )     ) xtitle("Years in the US") ytitle("")  ylab(, angle(horizontal)) graphregion(color(white)) name(figB1women,replace) 

	graph export "${result}FigB1_panelB.eps", replace 

restore




***********************************************************************************************************************	*						
* DISPLAY FIGURE 1 
************************************************************************************************************************			

graph replay fig1_A
graph replay fig1_B 

***********************************************************************************************************************	*						
* DISPLAY FIGURE A.1 
************************************************************************************************************************			

graph replay figB1men
graph replay figB1women

graph combine fig1_A fig1_B


